package com.ruoyi.heima.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.heima.domain.TbNewsType;
import com.ruoyi.heima.service.ITbNewsTypeService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 新闻类型Controller
 * 
 * @author liusm
 * @date 2025-09-13
 */
@RestController
@RequestMapping("/type")
public class TbNewsTypeController extends BaseController
{
    @Autowired
    private ITbNewsTypeService tbNewsTypeService;

    /**
     * 查询新闻类型列表
     */
    @RequiresPermissions("system:type:list")
    @GetMapping("/list")
    public TableDataInfo list(TbNewsType tbNewsType)
    {
        startPage();
        List<TbNewsType> list = tbNewsTypeService.selectTbNewsTypeList(tbNewsType);
        return getDataTable(list);
    }

    /**
     * 导出新闻类型列表
     */
    @RequiresPermissions("system:type:export")
    @Log(title = "新闻类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbNewsType tbNewsType)
    {
        List<TbNewsType> list = tbNewsTypeService.selectTbNewsTypeList(tbNewsType);
        ExcelUtil<TbNewsType> util = new ExcelUtil<TbNewsType>(TbNewsType.class);
        util.exportExcel(response, list, "新闻类型数据");
    }

    /**
     * 获取新闻类型详细信息
     */
    @RequiresPermissions("system:type:query")
    @GetMapping(value = "/{typeId}")
    public AjaxResult getInfo(@PathVariable("typeId") Integer typeId)
    {
        return success(tbNewsTypeService.selectTbNewsTypeByTypeId(typeId));
    }

    /**
     * 新增新闻类型
     */
    @RequiresPermissions("system:type:add")
    @Log(title = "新闻类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbNewsType tbNewsType)
    {
        return toAjax(tbNewsTypeService.insertTbNewsType(tbNewsType));
    }

    /**
     * 修改新闻类型
     */
    @RequiresPermissions("system:type:edit")
    @Log(title = "新闻类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbNewsType tbNewsType)
    {
        return toAjax(tbNewsTypeService.updateTbNewsType(tbNewsType));
    }

    /**
     * 删除新闻类型
     */
    @RequiresPermissions("system:type:remove")
    @Log(title = "新闻类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{typeIds}")
    public AjaxResult remove(@PathVariable Integer[] typeIds)
    {
        return toAjax(tbNewsTypeService.deleteTbNewsTypeByTypeIds(typeIds));
    }
}
